class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        if(pushed.size() != popped.size())
            return false;
        stack<int> st;
        int i = 0;
        for(auto& e : pushed)
        {
            st.push(e); // 不匹配就持续入，匹配就持续出
            while(!st.empty() && st.top() == popped[i])
            {
                st.pop();
                ++i;
            }
        }
        // return i == popped.size();
        return st.empty();
    }
};